#include "imgifsc.h"
#include "pgma_io.h"

#undef SHOWIMG // define para mostrar dados na tela

/*****************************************************
 * Main.c do trabalho de processamento de imagens
 *
 * Curso de Engenharia Eletrônica
 * Semestre 2015-1
 *
 * Desenvolvedor: Fernando S. Pacheco
 * IFSC 2014
 ******************************************************/

int main(void) {
	struct Img img1, img2, img3;
	/*memset(&img1, 0, sizeof(struct Img));
	memset(&img2, 0, sizeof(struct Img));
	memset(&img3, 0, sizeof(struct Img));*/
	int d;

	int constvalue;
	float alpha;

	pgma_read("ifsc.ascii.pgm", &img1.width, &img1.height, &img1.maxgray, &img1.data);
	pgma_read("saida.ascii.invert.pgm", &img2.width, &img2.height, &img2.maxgray, &img2.data);
	printf("1 invertImg\n2 fillImg\n3 blendImg\n");
	scanf("%d", &d);
#ifdef SHOWING
	int *dataptr;
	int i, j;
#endif
	switch (d) {
		case 1:
			invertImg(&img1);
			pgma_write("saida.ascii.invert.pgm", img1.width, img1.height, img1.data);
			if (TESTinvertImg()) {
					printf("PASS: invertImg OK\n");
				} else {
					printf("FAIL: invertImg FAIL *******\n");
				}
			break;

		case 2:
			printf("digite o valor:");
			scanf("%d", &constvalue);
			fillImg(&img1, constvalue, 255);
			img1.maxgray = 255;
			printf("Width %d, Height %d\n", img1.width, img1.height);
			pgma_write("saida.ascii.fillImg.pgm", img1.width, img1.height, img1.data);
#ifdef SHOWIMG
			dataptr=img1.data;
			for (i=0; i<img1.height; i++)
			{
				for (j=0; j<img1.width; j++)
				{
					printf("%d", *(dataptr));
					dataptr++;
				}
				printf("\n");
			}
#endif
			break;

		case 3:
			printf("digite o valor de alpha:");
			scanf("%f", &alpha);
			blendImg(&img3, &img1, &img2, alpha);
			printf("Width %d, Height %d\n", img1.width, img1.height);
			pgma_write("saida.ascii.blendImg.pgm", img3.width, img3.height, img3.data);
			puts("blend concluido!");
#ifdef SHOWIMG
			dataptr=img3.data;
			for (i=0; i<img3.height; i++)
			{
				for (j=0; j<img3.width; j++)
				{
					printf("%d", *(dataptr));
					dataptr++;
				}
				printf("\n");
			}
#endif
			break;
	}
	//chama função item B

	/*#ifdef SHOWIMG
	 int *dataptr;
	 int i, j;
	 dataptr=img3.data;
	 for (i=0; i<img3.height; i++) {
	 for (j=0; j<img3.width; j++) {
	 printf("%d", *(dataptr));
	 dataptr++;
	 }
	 printf("\n");
	 }
	 dataptr=img1.data;
	 for (i=0; i<img1.height; i++) {
	 for (j=0; j<img1.width; j++) {
	 printf("%d", *(dataptr));
	 dataptr++;
	 }
	 printf("\n");
	 }
	 #endif*/

	/*if (img1.data != NULL) free(img1.data); //desaloca espaço criado ao ler o arquivo
	if (img2.data != NULL) free(img2.data);
	if (img3.data != NULL) free(img3.data);*/

	//chama função de teste

	return 0;
}
